from time import sleep

from appium.webdriver.common.appiumby import AppiumBy

from src.common.base_app import BaseApp
from src.common.base_driver import BaseDriver


class WeWorkApp(BaseApp):
    _PAGE_LOAD_TIME = 1
    device_name = ":5555"
    app_package = "com.tencent.wework"
    app_start_activity = ".launch.LaunchSplashActivity"
    app_main_activity = ".launch.WwMainActivity"
    _ASK_DIALOG_OPTION = AppiumBy.ID, 'com.tencent.wework:id/cy_'

    def __init__(self, driver: BaseDriver = None):
        BaseApp.__init__(self, self.device_name, self.app_package, self.app_start_activity, driver)

    def goto_main_page(self):
        while self.driver.current_activity != self.app_main_activity:
            self.driver.back()
            ask_option = self.driver.find_el(*self._ASK_DIALOG_OPTION)
            if ask_option:
                ask_option.click()

        from src.page.main_page import MainPage
        return MainPage(self.driver)

    def load_wait(self):
        sleep(self._PAGE_LOAD_TIME)

